package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.EmpAttendanceAddDTO;
import org.jsola.hr.dto.EmpAttendanceUpdateDTO;
import org.jsola.hr.entity.EmpAttendanceDO;
import org.jsola.hr.query.EmpAttendanceQuery;
import org.jsola.hr.service.IEmpAttendanceService;
import org.jsola.hr.vo.EmpAttendanceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工考勤表
 *
 * @author zhr
 */
@Component
public class EmpAttendanceTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpAttendanceService empAttendanceService;

    /**
     * 生成add测试数据
     * @return EmpAttendanceAddDTO
     */
    public EmpAttendanceAddDTO getEmpAttendanceAddDTO(){
        EmpAttendanceAddDTO empAttendanceAddDTO = new EmpAttendanceAddDTO();
        empAttendanceAddDTO.setEmpId(getRandomValue("varchar",32));
        empAttendanceAddDTO.setCompanyId(getRandomValue("varchar",32));
        empAttendanceAddDTO.setDayWorkTime(SafeKit.getFloat(getRandomValue("float",5)));
        empAttendanceAddDTO.setIsWork(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empAttendanceAddDTO.setWorkDay(SafeKit.getFloat(getRandomValue("float",4)));
        empAttendanceAddDTO.setYearly(SafeKit.getInteger(getRandomValue("int",4)));
        empAttendanceAddDTO.setMonthly(SafeKit.getInteger(getRandomValue("int",2)));
        empAttendanceAddDTO.setDaily(SafeKit.getInteger(getRandomValue("int",2)));
        empAttendanceAddDTO.setEditBy(getRandomValue("varchar",50));
        return empAttendanceAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpAttendanceUpdateDTO
     */
    public EmpAttendanceUpdateDTO getEmpAttendanceUpdateDTO(EmpAttendanceVO empAttendanceVO){
        return empAttendanceService.selectDOById(empAttendanceVO.getId(), SITE_ID).to(EmpAttendanceUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpAttendanceQuery
     */
    public EmpAttendanceQuery getEmpAttendanceQuery() {
        EmpAttendanceQuery empAttendanceQuery = new EmpAttendanceQuery();
        List<EmpAttendanceDO> empAttendanceDOList = empAttendanceService.list(new EmpAttendanceDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empAttendanceDOList)) {
            EmpAttendanceDO empAttendanceDO = empAttendanceDOList.get(0);
            empAttendanceQuery = empAttendanceDO.to(EmpAttendanceQuery.class);
        }
        return empAttendanceQuery;
    }

    /**
     * 保存示例
     * @return EmpAttendanceVO
     */
    public EmpAttendanceVO saveEmpAttendanceExample(){
        EmpAttendanceAddDTO addDTO = this.getEmpAttendanceAddDTO();
        EmpAttendanceVO empAttendanceVO = empAttendanceService.save(addDTO,buildTokenUser());
        return empAttendanceVO;
    }


}

